package com.codebyorder.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codebyorder.entity.Doc;
import com.codebyorder.mapper.DocMapper;
import com.codebyorder.req.DocQueryReq;
import com.codebyorder.resp.DocQueryResp;
import com.codebyorder.resp.PageResp;
import com.codebyorder.service.DocService;
import com.codebyorder.util.CopyUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 29038
* @description 针对表【doc(文档)】的数据库操作Service实现
* @createDate 2022-12-14 09:06:42
*/
@Service
public class DocServiceImpl extends ServiceImpl<DocMapper, Doc>
    implements DocService{
    @Resource
    private DocMapper docMapper;
    private static final Logger LOG = LoggerFactory.getLogger(DocServiceImpl.class);


    @Override
    public PageResp<DocQueryResp> docToResp(DocQueryReq docQueryReq) {
        PageHelper.startPage(docQueryReq.getPage(), docQueryReq.getSize());//和第一个查询语句放在一起,请求参数
        List<Doc> docs = docMapper.selectByName(docQueryReq.getName());

        PageInfo<Doc> pageInfo = new PageInfo<>(docs);
        LOG.info("总行数:{}",pageInfo.getTotal());//返回给前端
        LOG.info("总页数:{}",pageInfo.getPages());

        List<DocQueryResp> docResp = CopyUtil.copyList(docs, DocQueryResp.class);
        PageResp<DocQueryResp> pageResp = new PageResp<>();
        pageResp.setTotal(pageInfo.getTotal());
        pageResp.setList(docResp);

        return pageResp;
    }

    @Override
    public void updateEbookInfo() {
        docMapper.updateEbookInfo();
    }
}




